package com.corticon.dialogs.util;
/**
 * generic function
 * @author heweiya
 *
 */
public class GenericFunction {
	private String questionNumberPix = "Q-";
	private String dialogNumberPix = "D-";
	/**
	 * Create question next number
	 * @param NextVal
	 * @return question Next number
	 */
	public String NextQuestionNumber(int NextVal){
		NextVal++;
		if (NextVal<10){
			return questionNumberPix + "0000"+NextVal;
		}
		if (NextVal>=10 && NextVal<100){
			return questionNumberPix + "000"+NextVal;
		}
		if (NextVal>=100 && NextVal<1000){
			return questionNumberPix + "00"+NextVal;
		}
		if (NextVal>=1000 && NextVal<10000){
			return questionNumberPix + "0"+NextVal;
		}
		if (NextVal>=10000 && NextVal<100000){
			return questionNumberPix +NextVal;
		}
		return questionNumberPix + "00001";
	}
	/**
	 * Create dialogs next number
	 * @param NextVal
	 * @return dialogs Next number
	 */
	public String NextDialogNumber(int NextVal){
		NextVal++;
		if (NextVal<10){
			return dialogNumberPix + "0000"+NextVal;
		}
		if (NextVal>=10 && NextVal<100){
			return dialogNumberPix + "000"+NextVal;
		}
		if (NextVal>=100 && NextVal<1000){
			return dialogNumberPix + "00"+NextVal;
		}
		if (NextVal>=1000 && NextVal<10000){
			return dialogNumberPix + "0"+NextVal;
		}
		if (NextVal>=10000 && NextVal<100000){
			return dialogNumberPix +NextVal;
		}
		return dialogNumberPix + "00001";
	}
    public String interceptStr(String str,int length){
        if (str.length()<= length){
            return str;
        }else{
            String myStr=str.substring(0,length);
            if (myStr.indexOf(" ")>=1){
                myStr = myStr.substring(0,myStr.lastIndexOf(" "));
                myStr += "...";
            }            
            return myStr;
        }       
    }
}
